package com.laxcen.basiclib.core.task.core.task;


import android.os.Handler;
import android.os.Looper;
import android.os.Message;

/**
 * 线程任务的处理类
 */
class TaskThreadHandler extends Handler {

    TaskThreadHandler(Looper looper) {
        super(looper);
    }

    @Override
    public void handleMessage(Message msg) {
        Object obj = msg.obj;
        if (obj != null && obj instanceof TaskMessage) {
            Runnable command = ((TaskMessage) obj).command;
            if (command != null) {
                command.run();
            }
        }
    }

    /**
     * 发送消息
     * @param taskMessage
     */
    public void sendMessage(TaskMessage taskMessage) {
        if (taskMessage == null) {
            return;
        }
        sendMessageDelayed(Message.obtain(this, taskMessage.what, taskMessage), taskMessage.delayTime + taskMessage.priority);
    }
}
